﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using QuickGraph;

namespace SuffixTreeView.Graph
{
    [DebuggerDisplay("Suffix={Suffix}; {Source.Label} -> {Target.Label}")]
    class SuffixTreeEdge : Edge<SuffixTreeNode>
    {
        public static string Text { get; set; }
        /// <summary>
        ///  Start of the suffix
        /// </summary>
        public int Start { get; private set; }

        /// <summary>
        /// End of the suffix
        /// </summary>
        public int End { get; private set; }

        /// <summary>
        /// Actual suffix
        /// </summary>
        public string Suffix 
        { 
            get
            {
                return Text.Substring(this.Start, this.End - this.Start + 1);
            }
        }

        public SuffixTreeEdge(int start, int end, SuffixTreeNode source, SuffixTreeNode target) : base(source, target)
        {
            if (string.IsNullOrWhiteSpace(Text))
            {
                throw new FormatException("Suffix Tree not initialized");
            }

            if (end < 0)
            {
                end = Text.Length - 1;
            }

            if (start > end)
            {
                throw new ArgumentOutOfRangeException("start > end");
            }

            this.Start = start;
            this.End = end;
        }
        
    }
}
